<?php
class GroupAction extends CommonAction
{
	public function found()
	{
		$group_dao = new GroupModel();
		$group_name = $_POST['name'];
		$introduction = $_POST['introduction'];
		$group_dao->found($_SESSION['user']['id'], $group_name, $introduction);
		$this->success("添加小组成功");
		
	}
	
	public function showAllGroups()
	{
		$group_dao = new GroupModel();
		$result = $group_dao->getAll(10);
		$this->assign("groups", $result['data']);
		$this->assign("page",$result['page']);
		$this->display();
	}
	
	/**
	 * Ajax方法，加入某个小组
	 */
	public function join()
	{
		$group_id = $_GET['group_id'];
		$group_user_dao = M('groupUser');
		$relation['group_id'] = $group_id;
		$relation['user_id'] = $_SESSION['user']['id'];
		$group_user_dao->add($relation);
		$this->ajaxReturn(null,null,1);
	}
	
	public function groupPage()
	{
		$group_id = $_GET['group_id'];
		$group_dao = new GroupModel();
		$group = $group_dao->getById($group_id);
		
		$book_dao = new BookModel();
		$books = $book_dao->getByGroupId($group_id);
		
		$this->assign("group", $group);
		$this->assign("books", $books);
		$this->display();
	}
	
	public function deleteMember() {
		$member_id = $_GET['member_id'];
		$group_id = $_GET['group_id'];
		$group_dao = new GroupModel();
		$group_dao->deleteMemeber($group_id, $member_id);
		$this->ajaxReturn(null,null,1);
	}
	
}

?>
